package com.jishaokang.controller;

import com.jishaokang.base.Result;
import com.jishaokang.model.dto.Chapter;
import com.jishaokang.model.dto.Live;
import com.jishaokang.service.LiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by NANA_Final on 2019/6/21.
 */
@RestController
@RequestMapping(value = "/api")
public class LiveController {

    @Autowired
    private LiveService liveService;

    @RequestMapping(value = "/all/live/selectLive",method = RequestMethod.POST)
    public Result selectLive(@RequestBody Live live) {
        return liveService.selectLive(live);
    }

    @RequestMapping(value = "/teacher/live/addLive",method = RequestMethod.POST)
    public Result teacherAddLive(@RequestBody Live live) throws IOException {
        return liveService.addLive(live);
    }

    @RequestMapping(value = "/liveServer/live/uploadLiveImage",method = RequestMethod.POST)
    public Result updateCourseImage(@RequestParam String token, @RequestParam Integer liveId, @RequestParam(value = "liveImageFile", required = false) MultipartFile liveImageFile, HttpServletRequest request) throws IOException {
        return liveService.uploadLiveImage(token,liveId,liveImageFile,request);
    }

    @RequestMapping(value = "/liveServer/live/selectLiveByLiveId",method = RequestMethod.POST)
    public Result selectLiveByLiveId(@RequestBody Live live) {
        return liveService.selectLiveByLiveId(live);
    }
    
    @RequestMapping(value = "/teacher/live/deleteLiveByUserId",method = RequestMethod.POST)
    public Result deleteLiveByUserId(@RequestBody Live live) throws IOException {
        return liveService.deleteLiveByUserId(live);
    }

    @RequestMapping(value = "/liveServer/live/deleteLiveByLiveId",method = RequestMethod.POST)
    public Result deleteLiveByLiveId(@RequestBody Live live) throws IOException {
        return liveService.deleteLiveByLiveId(live);
    }

    @RequestMapping(value = "/liveServer/live/updateWatchTotal",method = RequestMethod.POST)
    public Result updateWatchTotal(@RequestBody Live live) {
        return liveService.updateWatchTotal(live);
    }

}
